#!/bin/sh
uci -q batch <<-EOF >/dev/null
	delete ucitrack.@omr-tracker[-1]
	add ucitrack omr-tracker
	set ucitrack.@omr-tracker[-1].init="omr-tracker"
	commit ucitrack
EOF
if [ "$(uci -q get ucitrack.@network[-1].affects | grep omr-tracker)" = "" ]; then
	uci -q batch <<-EOF >/dev/null
		add_list ucitrack.@network[-1].affects="omr-tracker"
		commit ucitrack
	EOF
fi
if [ "$(uci -q get ucitrack.@shadowsocks-libev[-1].affects | grep omr-tracker)" = "" ]; then
	uci -q batch <<-EOF >/dev/null
		add_list ucitrack.@shadowsocks-libev[-1].affects="omr-tracker"
		commit ucitrack
	EOF
fi
if [ "$(uci -q get omr-tracker.defaults.interval_tries)" = "" ]; then
	uci -q batch <<-EOF >/dev/null
		set omr-tracker.defaults.interval_tries=1
		commit omr-tracker
	EOF
fi

if [ "$(uci -q get omr-tracker.shadowsocks)" != "" ]; then
	uci -q batch <<-EOF >/dev/null
		rename omr-tracker.shadowsocks=proxy
		uci set omr-tracker.proxy=proxy
		uci commit omr-tracker
	EOF
fi

if [ "$(uci -q get omr-tracker.proxy)" = "shadowsocks" ]; then
	uci -q batch <<-EOF >/dev/null
		uci set omr-tracker.proxy=proxy
		uci commit omr-tracker
	EOF
fi

if [ "$(uci -q get omr-tracker.proxy.hosts | grep '23.96.52.53')" != "" ]; then
	uci -q batch <<-EOF >/dev/null
		del_list omr-tracker.proxy.hosts='23.96.52.53'
		del_list omr-tracker.proxy.hosts='104.40.211.35'
		del_list omr-tracker.proxy.hosts='80.67.169.12'
		add_list omr-tracker.proxy.hosts='104.16.1.1'
		add_list omr-tracker.proxy.hosts='198.27.92.1'
		add_list omr-tracker.proxy.hosts='151.101.129.164'
		commit omr-tracker
	EOF
fi
if [ "$(uci -q get omr-tracker.proxy.hosts | grep '103.224.182.242')" != "" ]; then
	uci -q batch <<-EOF >/dev/null
		del_list omr-tracker.proxy.hosts='103.224.182.242'
		del_list omr-tracker.proxy.hosts='198.191.250.176'
		add_list omr-tracker.proxy.hosts='74.82.42.42'
		add_list omr-tracker.proxy.hosts='176.103.130.130'
		commit omr-tracker
	EOF
fi

if [ "$(uci -q get omr-tracker.defaults.wait_test)" = "" ]; then
	uci -q batch <<-EOF >/dev/null
		set omr-tracker.defaults.wait_test=1
		set omr-tracker.proxy.wait_test=1
		set omr-tracker.server.wait_test=1
		commit omr-tracker
	EOF
fi

exit 0